#####
#####
###     R session that creates Figure 1
#####
#####

library(lattice)

###
###   Read MDS configuration from file,
###   "mds config, with names.txt"
###

config <- read.table(file.choose(), header = T)


#####
#####
###     Reflect the horizontal axis, so liberal candidates
###     are on the left, etc.
#####
#####

config$dim1 <- -config$dim1


#####
#####
###     Graph basic MDS results, showing
###     point estimates for 13 political figures.
###
###     THIS IS FIGURE 1 IN THE ARTICLE.
#####
#####

config$names <- c("G. Bush", "Kerry", "Nader", "Cheney",
                  "Edwards", "L. Bush", "H. Clinton", "B. Clinton",
                  "Powell", "Ashcroft", "McCain", "Dem. Pty.", "Rep Pty.")

xyplot(dim2 ~ dim1, data = config,
       aspect = 1,
       panel = function( x, y) {
         panel.xyplot(x, y, col = "black")
         panel.text(x[c(1, 3, 6:11)],
                    y[c(1, 3, 6:11)] - .05, 
                    labels = config$names[c(1, 3, 6:11)], cex = .65)
         panel.text(x[4],
                    y[4] + .08, labels = "Cheney", 
                    cex = .65, adj = .2)
         panel.text(x[13], y[13] - .05,
                    labels = "Rep. Pty.", 
                    cex = .65, adj = .8)
         panel.text(x[2], y[2] + .08,
                    labels = "Kerry",
                    cex = .65, adj = .2)
         panel.text(x[12], y[12] - .05,
                    labels = "Dem. Pty.",
                    cex = .65, adj = 0)
         panel.text(x[5], y[5] - .05,
                    labels = "Edwards",
                    cex = .65, adj = .7)
       },
       ylim = c(-1.5, 2.5),
       xlim = c(-2, 2),
       xlab = "MDS Axis 1",
       ylab = "MDS Axis 2"
)
